package com.servlet;

import com.Dao.BookDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "AddBookServlet", value = "/AddBookServlet")
public class AddBookServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");
        // 获取要添加图书的信息
        String bookName = request.getParameter("bookName");
        String bookType = request.getParameter("bookType");
        String bookCard = request.getParameter("bookCard");
        String bookPress = request.getParameter("bookPress");
        String bookAuthor = request.getParameter("bookAuthor");
        int bookNum = Integer.parseInt(request.getParameter("bookNum"));
        BookDao bookdao = new BookDao();
        bookdao.addBook(bookName, bookType, bookCard, bookPress, bookAuthor, bookNum);
        response.sendRedirect("bookDisplayServlet");
    }
}
